/**
 * Jaxson ajax
 *
 * Copyright Remedy Interactive, licensed under Apache version 2 license:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0.html
 *
 * This notice must remain in all java source files.
 */
package org.jaxson.struts.encoder.excel;

import java.util.List;

import javax.servlet.ServletRequest;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

/**
 * Default implementation of a <code>org.jaxson.struts.encoder.excel.ExcelRenderer</code>.  
 * Simply sets the cell value without applying formatting.  Exposes workbook, sheet, and row
 * as protected members for subclasses.
 * 
 * recommended reading:
 * http://poi.apache.org/spreadsheet/quick-guide.html
 * 
 * @author Joe Maisel
 */
public class DefaultExcelRenderer implements ExcelRenderer
{
	protected HSSFWorkbook workbook;
	protected HSSFSheet sheet;
	protected HSSFRow row;
	protected boolean header;
	protected String sheetName;
	protected List<String> headerNames;
	protected boolean summarySheet;
	protected ServletRequest request;
	
	/**
	 * @see org.jaxson.struts.encoder.excel.ExcelRenderer#setCurrentCell(org.apache.poi.hssf.usermodel.HSSFCell, int, int)
	 */
	@Override
	public void setCurrentCell( HSSFCell cell, Object value, String getterName,boolean header )
	{
		cell.setCellValue( value + "" );
	}

	/**
	 * @see org.jaxson.struts.encoder.excel.ExcelRenderer#setCurrentRow(org.apache.poi.hssf.usermodel.HSSFRow)
	 */
	@Override
	public void setCurrentRow( HSSFRow row )
	{
		this.row = row;
	}

	/**
	 * @see org.jaxson.struts.encoder.excel.ExcelRenderer#setDefaultSheet(org.apache.poi.hssf.usermodel.HSSFSheet)
	 */
	@Override
	public void setDefaultSheet( HSSFSheet sheet )
	{
		this.sheet = sheet;
	}

	/**
	 * @see org.jaxson.struts.encoder.excel.ExcelRenderer#setWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)
	 */
	@Override
	public void setWorkbook( HSSFWorkbook workbook )
	{
		this.workbook = workbook;
	}

	/**
	 * @see org.jaxson.struts.encoder.excel.ExcelRenderer#getActiveSheet()
	 */
	@Override
	public HSSFSheet getActiveSheet()
	{
		return sheet;
	}

	/**
	 * @see org.jaxson.struts.encoder.excel.ExcelRenderer#expose(java.util.List)
	 */
	@Override
	public List<String> expose( List<String> getters )
	{
		return getters;
	}

	/**
	 * @see org.jaxson.struts.encoder.excel.ExcelRenderer#getRowIndex()
	 */
	@Override
	public int getRowIndex()
	{
		return 0;
	}

	/**
	 * @see org.jaxson.struts.encoder.excel.ExcelRenderer#hasHeaderRow(boolean)
	 */
	@Override
	public void setHeaderRow (boolean headerRow)
	{
		this.header=headerRow;
	}

	/**
	 * @see org.jaxson.struts.encoder.excel.ExcelRenderer#headers(java.util.List)
	 */
	@Override
	public void headers (List<String> headerNames)
	{
		this.headerNames=headerNames;
	}

	/**
	 * @see org.jaxson.struts.encoder.excel.ExcelRenderer#setSheetName(java.lang.String)
	 */
	@Override
	public void setSheetName (String sheetName)
	{
		this.sheetName=sheetName;
	}

	/**
	 * @see org.jaxson.struts.encoder.excel.ExcelRenderer#getHeaderNames(java.util.List)
	 */
	@Override
	public List<String> getHeaderNames ()
	{
		return headerNames;
	}

	/**
	 * @see org.jaxson.struts.encoder.excel.ExcelRenderer#getSheetName(java.lang.String)
	 */
	@Override
	public String getSheetName ()
	{
		return sheetName;
	}

	/**
	 * @see org.jaxson.struts.encoder.excel.ExcelRenderer#isHeaderRow(boolean)
	 */
	@Override
	public boolean isHeaderRow ()
	{
		return header;
	}

	/**
	 * @return the request
	 */
	public ServletRequest getRequest ()
	{
		return request;
	}

	/**
	 * @param request the request to set
	 */
	public void setRequest (ServletRequest request)
	{
		this.request = request;
	}


}
